import {
  OnGatewayConnection,
  SubscribeMessage,
  WebSocketGateway,
} from '@nestjs/websockets';
import type { WebSocket } from 'ws';

@WebSocketGateway({
  path: 'ws-demo',
})
export class WsDemoGateway implements OnGatewayConnection {
handleConnection(client: WebSocket, ...args: any[]) {
  client.on('message', (data: string) => {
    const msg = JSON.parse(data);
    if (msg.type === 'ping') {
      client.send(JSON.stringify({ type: 'pong' }));
    }
  });
}

}

// @WebSocketGateway({
//   path: 'ws-demo',
// })
// export class WsDemoGateway {
//   @SubscribeMessage('ping')
//   handleMessage() {
//     return 'pong';
//   }
// }
